﻿using System;

namespace MyBasicLib.Extensions
{
    public static class DateTimeExtension
    {
        private static readonly DateTime MaxDate = new DateTime(9999, 12, 31, 23, 59, 59, 999);
        private static readonly DateTime MinDate = new DateTime(1900, 1, 1);

        public static bool IsValid(this DateTime target)
        {
            return (target >= MinDate) && (target <= MaxDate);
        }

        public static DateTime GetValidDate(this DateTime target)
        {
            return IsValid(target) ? target : MinDate;
        }

        public static DateTime GetValidDate(this DateTime target, DateTime defaultDate)
        {
            return IsValid(target) ? target : defaultDate;
        }
    }
}